<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <!-- 在li上用v-for循环渲染出list中所有的数据(有id用id) -->
    <li :class="{ completed: item.isDone }" v-for="item in list" :key="item.id">
      <div class="view">
        <input class="toggle" type="checkbox" v-model="item.isDone" />
        <label>{{ item.name }}</label>
        <button @click="delTask(item.id)" class="destroy"></button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  // 通过props来接收父级传过来的list
  props: ["list"],
  methods: {
    delTask(id) {
      // console.log(id);
      this.$emit("delTask", id);
    },
  },
};
</script>